<template>
	<view>
		<view class="list" v-for="(item,index) in list">
			<view class="tit">{{item.type_text}}</view>
			<view>变动金额：<text style="color: #FF6543;font-weight: bold;">{{item.money}}</text></view>
			<view>变动后金额：<text style="color: green;font-weight: bold;">{{item.user_after_money}}</text></view>
			<view class="time">{{item.create_time}}</view>
		</view>
		<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
	</view>
</template>

<script>
	import {
		moneyLog,
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
			};
		},
		onLoad() {
			this.getlist()
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
				} = that;
				let obj = {
					size: offset,
					page: page + 1,
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await moneyLog(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							console.log((888))
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
.list{
	background: white;
	padding: 20rpx;
	margin: 20rpx;
	font-size: 26rpx;
	view{
		margin-bottom: 10rpx;
	}
	.tit{
		font-size: 30rpx;
		font-weight: bold;
		margin-bottom: 15rpx;
	}
	.time{
		color: gray;
		font-size: 24rpx;
	}
}
</style>
